/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */
package l1j.server.server.serverpackets;

public class S_ServerMessage extends ServerBasePacket {
	private static final String S_SERVER_MESSAGE = "[S] S_ServerMessage";

	public static final int NO_PLEDGE = 208;

	public static final int CANNOT_GLOBAL = 195;

	public static final int CANNOT_BOOKMARK_LOCATION = 214;

	public static final int USER_NOT_ON = 73;

	public static final int NOT_ENOUGH_MP = 278;

	public static final int YOU_FEEL_BETTER = 77;

	public static final int YOUR_WEAPON_BLESSING = 693;

	public static final int YOUR_Are_Slowed = 29;

	private byte[] _byte = null;

	public S_ServerMessage(final int type) {
		this.buildPacket(type, null, null, null, null, null, 0);
	}

	public S_ServerMessage(final int type, final String msg1) {
		this.buildPacket(type, msg1, null, null, null, null, 1);
	}

	public S_ServerMessage(final int type, final String msg1, final String msg2) {
		this.buildPacket(type, msg1, msg2, null, null, null, 2);
	}

	public S_ServerMessage(final int type, final String msg1,
			final String msg2, final String msg3) {
		this.buildPacket(type, msg1, msg2, msg3, null, null, 3);
	}

	public S_ServerMessage(final int type, final String msg1,
			final String msg2, final String msg3, final String msg4) {
		this.buildPacket(type, msg1, msg2, msg3, msg4, null, 4);
	}

	public S_ServerMessage(final int type, final String msg1,
			final String msg2, final String msg3, final String msg4,
			final String msg5) {

		this.buildPacket(type, msg1, msg2, msg3, msg4, msg5, 5);
	}

	/**
	 * 服務器訊息(NPC對話)
	 * 
	 * @param winName
	 * @param color
	 * <br>
	 *            <font color="#bdaaa5">\\fR <b>顏色範例</b></font><br>
	 *            <font color="#739e84">\\fS <b>顏色範例</b></font><br>
	 *            <font color="#7b9e7b">\\fT <b>顏色範例</b></font><br>
	 *            <font color="#7b9aad">\\fU <b>顏色範例</b></font><br>
	 *            <font color="#a59ac6">\\fV <b>顏色範例</b></font><br>
	 *            <font color="#ad92b5">\\fW <b>顏色範例</b></font><br>
	 *            <font color="#b592ad">\\fX <b>顏色範例</b></font><br>
	 *            <font color="#bd9a94">\\fY <b>顏色範例</b></font><br>
	 */
	public S_ServerMessage(final String name) {
		this.writeC(S_OPCODE_NPCSHOUT);
		this.writeC(0x00);// 顏色
		this.writeD(0x00000000);
		this.writeS(name);
	}

	private void buildPacket(final int type, final String msg1,
			final String msg2, final String msg3, final String msg4,
			final String msg5, final int check) {

		this.writeC(S_OPCODE_SERVERMSG);
		this.writeH(type);

		if (check == 0) {
			this.writeC(0);
		} else if (check == 1) {
			this.writeC(1);
			this.writeS(msg1);
		} else if (check == 2) {
			this.writeC(2);
			this.writeS(msg1);
			this.writeS(msg2);
		} else if (check == 3) {
			this.writeC(3);
			this.writeS(msg1);
			this.writeS(msg2);
			this.writeS(msg3);
		} else if (check == 4) {
			this.writeC(4);
			this.writeS(msg1);
			this.writeS(msg2);
			this.writeS(msg3);
			this.writeS(msg4);
		} else {
			this.writeC(5);
			this.writeS(msg1);
			this.writeS(msg2);
			this.writeS(msg3);
			this.writeS(msg4);
			this.writeS(msg5);
		}
	}

	@Override
	public byte[] getContent() {
		if (this._byte == null) {
			this._byte = this._bao.toByteArray();
		}

		return this._byte;
	}

	@Override
	public String getType() {
		return S_SERVER_MESSAGE;
	}
}
